<?php
/*
@author: wjf
@contact: Hurrican
@software: PhpStorm
@create: 2024/4/18 15:22
*/
declare(strict_types=1);
namespace app\common\service\game;
use Tencent\TLSSigAPIv2;
use function DI\string;

class Live{

    protected $sdkAppid;
    protected $sdkAppsecret;

    public function __construct()
    {
        $this->sdkAppid = '1600032733';
        $this->sdkAppsecret = '8c83d9be23f93ac0eec3601093fb1835ce6434d2eda98d48f4a79658b4911eab';
    }

    /**签名
     * @return string
     * @throws \Exception
     */
    public function sign($device): string
    {
        $api = new TLSSigAPIv2($this->sdkAppid, $this->sdkAppsecret);
        return $api->genUserSig((string)$device);
    }

    /**生成推流地址
     * @param $room_id
     * @param int $device
     */
    public function creatStreamUrl($room_id,$device = '1001'):string
    {
        $url = 'rtmp://rtmp.rtc.qq.com/push/'.$room_id;
        $params = [
            'sdkappid' => $this->sdkAppid,
            'userid' => $device,
            'usersig' => $this->sign($device)
        ];
        return $url.'?'.spliceString($params);
    }



}
